TUNING.SKILL_THRESHOLDS = {
    3, -- 5, --1
    3, -- 8, --2
    4, -- 8, --3
    4, -- 8, --4
    4, --10, --5
    5, --10, --6
    5, --10, --7
    5, --10, --8
    5, --10, --9
    5, --12, --10
    5, --12, --11
    5, -- 12, --12
    5, --15, --13
    5, -- 15, --14
    5, -- 15, --15
    6, -- 18, --16
    6, -- 18, --17
    6, -- 18, --18
    6, -- 18, --19
    6, -- 18, --20
    6, -- 18, --21
    6, -- 18, --22
    6, -- 18, --23
    6, -- 18, --24
    6, -- 18, --25
    6, -- 18, --26
    6, -- 18, --27
    6, -- 18, --28
    6, -- 18, --29
    6, -- 18, --30
}

TUNING.FIXME_DO_NOT_USE_FOR_MODS_NEW_MAX_XP_VALUE = 158


AddPrefabPostInit('woodie',function (inst)
    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent('woodie_skill_tree_newunlock_data')

    inst:ListenForEvent('oneat',
    ---comment
    ---@param this ent
    ---@param data event_data_oneat
    function (this, data)
        local food = data and data.food or nil
        if food and food.prefab == 'monsterlasagna' then
            if inst.components.woodie_skill_tree_newunlock_data then
                inst.components.woodie_skill_tree_newunlock_data:ForUnlock_EatMonsterLasagna()
            end
        end
    end)

    inst:ListenForEvent('finishedwork',
    ---comment
    ---@param this ent
    ---@param data event_data_finishedwork
    function (this, data)
        local target = data and data.target or nil
        if target then
            inst.components.woodie_skill_tree_newunlock_data:ForUnlock_WorkFinish(target)
        end
    end)

    ---comment
    ---@param this ent
    ---@param data event_data_killed_ming_woodie_skilltree_participate
    local function onkill(this,data)
        local victim = data and data.victim or nil
        if victim then
            inst.components.woodie_skill_tree_newunlock_data:ForUnlock_KillMob(victim)
        end
    end

    inst:ListenForEvent('killed',onkill)
    inst:ListenForEvent('killed_ming_woodie_skilltree_participate',onkill)

    inst:ListenForEvent('builditem',
    ---comment
    ---@param this ent
    ---@param data event_data_builditem
    function (this, data)
        local item = data and data.item or nil
        local recipe = data and data.recipe or nil
        if item and recipe then
            inst.components.woodie_skill_tree_newunlock_data:ForUnlock_BuildItem(item,recipe)
        end
    end)

end)

-- 变身时处理
AddComponentPostInit('wereness',
---comment
---@param self component_wereness
function (self)
    local old_SetWereMode = self.SetWereMode
    function self:SetWereMode(weremode,...)
        if self.inst.prefab == 'woodie' and self.inst.components.woodie_skill_tree_newunlock_data and weremode ~= nil then
            if weremode == 'beaver' or weremode == 'moose' or weremode == 'goose' then
                self.inst.components.woodie_skill_tree_newunlock_data:ForUnlock_Henshin(weremode)
            end
        end
        return old_SetWereMode ~= nil and old_SetWereMode(self,weremode,...) or nil
    end
end)

-- 不让玩家加点
AddClassPostConstruct('widgets/redux/skilltreewidget',function (self, ...)
    if self.target and self.target == 'woodie' then
        if self.root.infopanel.activatebutton then
            self.root.infopanel.activatebutton.Show = function(...)
                return self.root.infopanel.activatebutton:Hide()
            end
        end
    end
end)

-- 覆盖技能树
local new_skilltree_woodie = require('core_ming_woodie_skilltree/hooks/skilltree_woodie')
local skilltree_defs = require("prefabs/skilltree_defs")
local avatarid = 'woodie'

if new_skilltree_woodie then --给角色创建一个技能树
    local data = new_skilltree_woodie(skilltree_defs.FN)
    if data then
        skilltree_defs.CreateSkillTreeFor(avatarid, data.SKILLS)
        skilltree_defs.SKILLTREE_ORDERS[avatarid] = data.ORDERS
    end
end

-- 快速捡拾者1：完成采集动作40次
AddComponentPostInit('pickable',
---comment
---@param self component_pickable
function (self)
    local old_Pick = self.Pick
    function self:Pick(picker,...)
        if picker ~= nil and picker.prefab == 'woodie' then
            if picker.components.woodie_skill_tree_newunlock_data then
                picker.components.woodie_skill_tree_newunlock_data:ForUnlock_QuickPick()
            end
        end
        return old_Pick ~= nil and old_Pick(self,picker,...) or nil
    end
end)

-- 部分不好判断死亡的生物
for _, v in ipairs({
    'daywalker',
    'alterguardian_phase3',
}) do
    AddPrefabPostInit(v, function(inst)
        if not TheWorld.ismastersim then
            return inst
        end
        if not inst.components.lootdropper then
            inst:AddComponent('lootdropper')
        end
        local old_lootsetupfn = inst.components.lootdropper.lootsetupfn
        inst.components.lootdropper:SetLootSetupFn(function (...)
            local res = old_lootsetupfn ~= nil and {old_lootsetupfn(...)} or {}
            if inst._ming_woodie_skilltree_participate_kill_tbl ~= nil then
                for p,_ in pairs(inst._ming_woodie_skilltree_participate_kill_tbl) do
                    if p and p.prefab == 'woodie' then
                        if p.components.woodie_skill_tree_newunlock_data then
                            p.components.woodie_skill_tree_newunlock_data:ForUnlock_KillMob(inst)
                        end
                    end
                end
            end
            return unpack(res)
        end)
    end)
end


